package 力扣日常刷题.木22一月.第09天0117;

/**
 * @author 帅小伙
 * @date 2022/1/17
 * @description
 * https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/solution/zui-jia-mai-mai-gu-piao-shi-ji-han-leng-dong-qi-4/
 */
public class Demo04动态规划中等买卖股票含有冷冻期 {


    public int maxProfit(int[] prices) {
        int n = prices.length;
        // 1 持有股票   2 不持有股票在冷冻期    3 不持有不在冷冻期  最大收益
        int[][] dp  = new int[n][3];
        dp[0][0] = -prices[0];
        for (int i = 1; i < n; i++) {
            dp[i][0] = Math.max(dp[i-1][0],dp[i-1][2]-prices[i]);
            dp[i][1] = dp[i-1][0] + prices[i];
            dp[i][2] = Math.max(dp[i-1][1],dp[i-1][2]);
        }
        return Math.max(dp[n-1][1],dp[n-1][2]);
    }
}
